package com.haierp.service.yitao.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.haierp.enums.ItemStatus;
import com.haierp.exception.ErpCommonException;
import com.haierp.model.Item;
import com.haierp.service.yitao.YiTaoProductService;
import com.haierp.util.yitao.YtDimensionCodeUtil;
import com.haierp.util.yitao.YtProductDataUtils;
import com.haierp.vo.ItemQueryVO;
import com.youzan.open.sdk.gen.v3_0_0.model.YouzanItemCreateResult;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IYtProductServiceImpl implements YiTaoProductService {

    protected Logger logger = LogManager.getLogger(getClass());

    /**
     * 创建商品
     *
     * @param
     * @return
     */
    @Override
    public JSONObject yitaoItemCreate(JSONObject jsonObject ) {
        String path = "/yitao/productCmsInfo/saveProductInfoAndImg";
        JSONObject result = null;
        try {
            result = YtDimensionCodeUtil.doPost(path, jsonObject);
            logger.info("返回参数:{}", result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 商品批零上架/下架
     *
     * @param map
     * @return
     */
    @Override
    public String yitaoItemUpdateListing(Map<String, Object> map) {
        String path = "/yitao/productCmsInfo/updateProductSaleByCode";
        String result = null;
        try {
            result = YtDimensionCodeUtil.yitaoHttpPostRequest(path, map, "POST");
            logger.info("返回参数:{}", result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 同步库存
     *
     * @param map
     * @return
     */
    @Override
    public String yitaoItemSkuUpdate(Map<String, Object> map) {

        String path = "/yitao/productCmsSku/updateSkuInventory";
        String result = null;
        try {
            result = YtDimensionCodeUtil.yitaoHttpPostRequest(path, map, "POST");
            logger.info("返回参数:{}", result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
        public static void main(String[] args) {
            String path = "/yitao/productCmsSku/updateSkuInventory";
            Map<String, Object> map = new HashMap<>();
            map.put("productId", 1);
            map.put("skuId", 1);
            map.put("entityStock", 55);//实际库存
            String result = null;
            try {
                result = YtDimensionCodeUtil.yitaoHttpPostRequest(path, map, "POST");
                System.out.println(result);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


   /* public static void main(String[] args) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("productName", "123");
        jsonObject.put("productEnName", "123");
        jsonObject.put("brandName", "品牌");//品牌
        jsonObject.put("categoryId", "1");//类目
        jsonObject.put("categoryName", "产地名");
        jsonObject.put("builtPlaceName", "产地");//产地
        jsonObject.put("currency", "1");//币种
        jsonObject.put("markerPrice", "435");//价格区间
        jsonObject.put("shopId", "-1");//所属门店
        jsonObject.put("productMainImgUrl", "/123");//商品主图
        jsonObject.put("productDetail", "345");//商品详情
        jsonObject.put("freightFee", "33");//运费
        jsonObject.put("articleNumber", "33");//货号
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("sourceSkuId", 23);
        jsonObject1.put("sourceSkuCode", "12343");//sku
        jsonObject1.put("productId", 1);
        jsonObject1.put("colour", "红色");//颜色
        jsonObject1.put("productSize", "24");//尺寸
        jsonObject1.put("salesPrice", 35);//售价
        jsonObject1.put("wholesalePrice", 26);//批发价
    *//*    jsonObject1.put("discount", 35.00);//折扣率*//*
        jsonObject1.put("entityStock", 52);//实库
        jsonObject1.put("imageUrl", "124566");//需处理
        jsonArray.add(jsonObject1);
        jsonObject.put("productSkuList",jsonArray);

        String path = "/yitao/productCmsInfo/saveProductInfoAndImg";

        JSONObject result = null;
            try {
                result = YtDimensionCodeUtil.doPost(path, jsonObject);
                System.out.println(result);
            } catch (Exception e) {
                e.printStackTrace();
            }


    }*/


}
